home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-03-04 | 8.1 KB | 291 lines | [TEXT/PJMM] |
- PROGRAM DailyOrganiser;
-
- { Daily Organiser is a hierarchical joke program, showing what may }
- { happen if programmers go too far. It uses the new hierarchical }
- { menus in system 4.1 and later (it bombs on earlier systems). }
-
- { Hierarchical menus are formed like any other menu, but are inserted }
- { with 'InsertMenu' before menu ID -1, and referenced by a menu item }
- { with command key equivalent $1B, with the check mark pointing to }
- { the menu to be shown. }
-
- { If an item is chosen which has a hierarchical menu attached, }
- { 'MenuSelect' returns a zero, as if no item was chosen. Similarly, if }
- { an item with hierarchical menu attached is disabled, the hierarchical }
- { menu does not appear. }
-
- { Daily Organiser uses the International Utilities to obtain the names of }
- { months, and to calculate times. Therefore, if used in, say, Germay }
- { where a 24hr clock is used, the months will appear in German and }
- { the times in the 24hr clock system. Pretty neat, eh? }
-
- { To use, simply compile, add accompanying resources, and set the }
- { creator to 'Dag!'. Enjoy! }
-
- { Daily Organiser is © 1987 by John Rotenstein. }
- { Originally programming in LightSpeed Pascal. }
- { This source code, relevant resources and complete applications may }
- { be distributed for non-profit purposes. Feedback welcome. }
-
- { Now, on with the show… }
-
-
- CONST
- hMenuCmd = $1B; {itemCmd == $1B ==> hierarchical menu}
- hierMenu = -1; {a hierarchical menu - for InsertMenu call}
-
- appleMenu = 1; { ID numbers of menus }
- fileMenu = 2;
- editMenu = 3;
- dailyMenu = 10;
- jobMenu = 14;
-
- VAR
- Alrt : integer;
- appleMenuH, fileMenuH, editMenuH, dailyMenuH : MenuHandle;
- SysStrH : StringHandle;
- SysStr : Str255;
- quitting : Boolean;
-
- {-----------------------------------------------------------}
-
- PROCEDURE SetItemCmd (menu : MenuHandle;
- item : INTEGER;
- cmdChar : CHAR);
- INLINE
- $A84F; { New command added for hierarchical usage }
-
- {-----------------------------------------------------------}
-
- PROCEDURE Init; { All the interesting stuff }
-
- CONST
- MBAR = 1; { ID of MBAR resource }
-
- VAR
- menuBar : Handle;
- Intl : Intl1Hndl; { Handle to international resource }
- theString : Str255;
- index : integer;
- indexL, time : longint;
- menuH : MenuHandle;
-
- BEGIN
- quitting := false;
-
- menuBar := GetNewMBar(MBAR);
- SetMenuBar(menuBar);
- DisposHandle(menuBar);
-
- appleMenuH := GetMHandle(appleMenu); { Get menu handles of menus }
- fileMenuH := GetMHandle(fileMenu); { loaded with 'SetMenuBar'. }
- editMenuH := GetMHandle(editMenu);
- dailyMenuH := GetMHandle(dailyMenu);
- AddResMenu(appleMenuH, 'DRVR'); { Add DAs }
- DrawMenuBar;
-
- { Side Note: If you add menus after 'DrawMenuBar', you can get an interesting }
- { effect with the new system. See the application 'Magic Menus' for an e.g. }
-
- FOR index := 4 TO 7 DO
- InsertMenu(GetMenu(index), hierMenu);
-
- { The hierarchical menus can't be added with 'Get/SetMenuBar'. }
- { They must be added with InsertMenu, before menu ID '-1'. }
-
- index := 1;
- FOR indexL := 1987 TO 1992 DO { Change as appropriate }
- BEGIN
- NumtoString(indexL, theString); { Converts from # to string }
- AppendMenu(dailyMenuH, theString);
- SetItemCmd(dailyMenuH, index, chr(hMenuCmd)); { Make hierarchical }
- SetItemMark(dailyMenuH, index, chr(11)); { Link each item to menu ID 11 }
- index := index + 1
- END;
-
- Intl := Intl1Hndl(IUGetIntl(1));
- menuH := NewMenu(11, 'Month');
- InsertMenu(menuH, hierMenu);
- WITH Intl^^ DO
- FOR index := 1 TO 12 DO
- BEGIN
- AppendMenu(menuH, months[index]); { Months from Intl resource }
- SetItemCmd(menuH, index, chr(hMenuCmd)); { Make hierarchical }
- SetItemMark(menuH, index, chr(12)) { Link each item to menu ID 12 }
- END;
- DisposHandle(Handle(Intl));
-
- menuH := NewMenu(12, 'Day');
- InsertMenu(menuH, hierMenu);
- FOR index := 1 TO 31 DO
- BEGIN
- NumToString(index, theString);
- AppendMenu(menuH, theString);
- SetItemCmd(menuH, index, chr(hMenuCmd)); { Make hierarchical }
- SetItemMark(menuH, index, chr(13)) { Link each item to menu ID 13 }
- END;
-
- { The time routine below calculates the time by half hour intervals (1800 secs) }
- { and then asks the International Routines to calculate the ASCII readout. }
- { Longints must be used in these time calculations, but normal integers for menus.}
-
- menuH := NewMenu(13, 'Hour');
- InsertMenu(menuH, hierMenu);
- index := 1;
- FOR indexL := 14 TO 40 DO
- BEGIN
- time := indexL * 1800;
- IUTimeString(time, false, theString);
- AppendMenu(menuH, theString);
- SetItemCmd(menuH, index, chr(hMenuCmd)); { Make hierarchical }
- SetItemMark(menuH, index, chr(14)); { Link each item to menu ID 13 }
- index := index + 1
- END;
-
- { Note that no serious program would link every menu item to the same }
- { hierarchical menu. There is no way of knowing which route the user took }
- { to arrive at the menu selection. Separate menus would have to be }
- { created, but these could be generated with the one menu resource, but }
- { with different IDs! }
-
- menuH := NewMenu(14, 'Jobs');
- InsertMenu(menuH, hierMenu);
- index := 1;
- REPEAT
- GetIndString(theString, 1, index);
- IF theString <> '' THEN
- AppendMenu(menuH, theString);
- index := index + 1
- UNTIL theString = '';
-
- { You may add jobs by adding entries into the STR# 1 resource. }
-
- END; {Init}
-
- {-----------------------------------------------------------}
-
- PROCEDURE AlrtProc (alertnum : integer);
-
- { Poorly named. Actually brings up the requested dialog box and waits for }
- { a key press, mouse down, or disk-insert event. Caters for background }
- { updating of windows in MultiFinder by continually calling 'EventAvail' }
- { and is friendly to DAs by calling 'SystemTask'. }
-
- VAR
- theDialog : DialogPtr;
- oldPort : GrafPtr;
- theEvt : EventRecord;
-
- BEGIN
-
- GetPort(oldPort);
- theDialog := GetNewDialog(alertnum, NIL, pointer(-1));
- SetPort(theDialog);
- DrawDialog(theDialog); { Must manually draw as no dialog routines used }
- HiliteMenu(0); { Turn off menu hilight }
- REPEAT
- SystemTask
- UNTIL (EventAvail(mDownMask + keyDownMask + diskMask, theEvt)) AND (theEvt.what <> nullEvent);
- CloseDialog(theDialog);
- SetPort(oldPort)
-
- END; {AlrtProc}
-
- {-----------------------------------------------------------}
-
- PROCEDURE DoCommand (mResult : longint);
-
- { Handles menu choices }
-
- VAR
- theItem, theMenu, temp : integer;
- name : Str255;
- tempB : boolean;
-
- BEGIN
- theItem := LoWord(mResult);
- theMenu := HiWord(mResult);
-
- CASE theMenu OF
-
- appleMenu :
- IF theItem <> 1 THEN
- BEGIN
- GetItem(appleMenuH, theItem, name);
- temp := OpenDeskAcc(name);
- END;
-
- fileMenu :
- quitting := true;
-
- editMenu :
- tempB := SystemEdit(theItem - 1);
-
- jobMenu :
- AlrtProc(1);
-
- OTHERWISE { This command may not be available in all versions of pascal }
- ; {ignore it}
-
- END; {of menu case}
- HiliteMenu(0)
-
- END; {DoCommand}
-
- {-----------------------------------------------------------}
-
- PROCEDURE DoEvent;
- VAR
- theEvent : EventRecord;
- theChar : Char;
- whichWindow : WindowPtr;
-
- BEGIN
- IF GetNextEvent(everyEvent, theEvent) THEN
- CASE theEvent.what OF
-
- mouseDown :
-
- CASE FindWindow(theEvent.where, whichWindow) OF
-
- inSysWindow :
- SystemClick(theEvent, whichWindow);
-
- inMenuBar :
- DoCommand(MenuSelect(theEvent.where));
-
- OTHERWISE
- ; {ignore it}
-
- END; {mouseDown}
-
- OTHERWISE
- ; {ignore it}
-
- END; {case event}
-
- END; {DoEvent}
- {-----------------------------------------------------------}
-
- BEGIN
- SysStrH := GetString(0); { Get system version string}
- SysStr := SysStrH^^;
- DisposHandle(Handle(SysStrH));
-
- { This alert box ensures the required system is being used. }
- { Once the 'SysEnvirons' call gets going, it will be a simple }
- { process to automate, but until then… }
-
- ParamText(SysStr, '', '', '');
- InitCursor;
- Alrt := Alert(1, NIL);
- IF Alrt = 1 THEN { 'Continue' }
-
- BEGIN
- Init; { Do once-only stuff }
- REPEAT
- DoEvent { Do main loop }
- UNTIL quitting
- END
-
- END. {DailyOrganiser}